<template>
  <div class="box">
    <div v-for="(item,index) in titles" class="tab-control-item">
      <span @click="itemClick(index)" :class="{active:index===currentIndex}">{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabControl",
    props:{
      titles:{
        type:Array,
        default(){return ['流行','新款','精选']}
      }
    },
    data(){
      return{
        currentIndex:0
      }
    },
    methods:{
      itemClick(index){
        this.currentIndex = index
        this.$emit('tabClick',index)
      }
    }
  }
</script>

<style scoped>
  .box{
    width: 100%;
    display: flex;
    text-align: center;
  }
  .tab-control-item{
    line-height: 40px;
    font-size: 15px;
    flex: 1;
  }
  .active{
    border-bottom: #ff5777 solid 2px;
    color: #ff5777;
  }
  span{
    padding: 5px;
  }
</style>